<?php


namespace app\admin\services;


use app\common\caches\GameCache;
use app\common\models\Admin;
use app\common\models\Game;
use app\Request;

class AdminService
{
    private $adminModel;

    public function __construct(Admin $adminModel)
    {
        $this->adminModel = $adminModel;
    }

    public function create(Request $request)
    {
        $data = $request->post(['username', 'name', 'password', 'avatar']);
        return $this->adminModel->createRow($data);
    }

    public function search(Request $request)
    {
        $name = $request->get('name', '');
        if (!empty($name)){
            $this->adminModel = $this->adminModel->where('name', '=', $name);
        }
        $limit = $request->get('limit', 10);
        $page = $request->get('page', 1);
        return $this->adminModel->order('id')->paginate([
            'list_rows' => $limit,
            'page' => $page
        ]);
    }

    public function update(Request $request, $id)
    {

    }

    public function delete($id)
    {

    }

    public function changePwd($id)
    {

    }
}
